<template>
  <div class="detail">
    <el-card>
      <div style="text-align: right">
        <el-button @click="toPrint">打印页面</el-button>
      </div>
      <el-tabs v-model="activeName">
        <el-tab-pane label="登陆账号设置" name="first">
          <el-form class="myform" :model="form" label-width="100px">
            <el-form-item label="姓名">
              <el-input v-model="form.username"></el-input>
            </el-form-item>
            <el-form-item label="密码">
              <el-input v-model="form.password" type="password"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="update">更新</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情" name="second">
          <userInfo></userInfo>
        </el-tab-pane>
        <el-tab-pane label="岗位信息" name="third">
          <jobInfo></jobInfo>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { getInfoByIdApi, saveInfoByIdApi } from '@/api/employees'
export default {
  data() {
    return {
      activeName: 'first',
      form: {
        username: '',
        password: ''
      },
      id: this.$route.params.id
    }
  },
  methods: {
    // 打印跳转页面
    toPrint() {
      this.$router.push(`/employees/print?active=${this.activeName}`)
    },
    // 提交更改后的数据
    async update() {
      await saveInfoByIdApi(this.form)
      this.$message.success('更新用户数据成功')
    },
    async getInfoById() {
      const res = await getInfoByIdApi(this.id)
      this.form = res.data.data
    }
  },
  created() {
    this.getInfoById()
  },
  components: {
    userInfo: () => import('../components/user-info.vue'),
    jobInfo: () => import('../components/job-info.vue')
  }
}
</script>

<style lang="scss">
.detail {
  margin: 20px;
  .myform {
    width: 400px;
    margin-top: 50px;
    margin-left: 250px;
  }
}
</style>
